﻿package morn.core.managers
{
    import flash.events.*;
    import flash.utils.*;

    public class RenderManager extends Object
    {
        private var _methods:Dictionary;

        public function RenderManager()
        {
            this._methods = new Dictionary();
            return;
        }// end function

        private function invalidate() : void
        {
            App.stage.addEventListener(Event.RENDER, this.onValidate);
            App.stage.addEventListener(Event.ENTER_FRAME, this.onValidate);
            if (App.stage)
            {
                App.stage.invalidate();
            }
            return;
        }// end function

        private function onValidate(event:Event) : void
        {
            App.stage.removeEventListener(Event.RENDER, this.onValidate);
            App.stage.removeEventListener(Event.ENTER_FRAME, this.onValidate);
            this.renderAll();
            return;
        }// end function

        public function renderAll() : void
        {
            var _loc_1:Object = null;
            for (_loc_1 in this._methods)
            {
                
                this.exeCallLater(_loc_1 as Function);
            }
            return;
        }// end function

        public function callLater(param1:Function, param2:Array = null) : void
        {
            if (this._methods[param1] == null)
            {
                this._methods[param1] = param2 || [];
                this.invalidate();
            }
            return;
        }// end function

        public function exeCallLater(param1:Function) : void
        {
            var _loc_2:Array = null;
            if (this._methods[param1] != null)
            {
                _loc_2 = this._methods[param1];
                delete this._methods[param1];
                param1.apply(null, _loc_2);
            }
            return;
        }// end function

    }
}
